<?php
/*****************************************************************************
**	Файл:	Главная страница сервера(ов)									**
**	Автор:	Dark Dayver														**
**	Версия:	1.0b															**
**	Дата:	25/12-2009														**
*****************************************************************************/
if (IN_P_ENIGMA)
{
	die('HACK!');
}

$template->array_data['IF_SERVER_NO'] = SERVER_NO;
$static = $work->get_stat();
$title .= ' - ' . $language->title['main'];

if (SERVER_NO)
{
	$home = str_replace('s' . SERVER_NO . '.', '', $work->config['site_url']);
	$local_menu[0]['U_URL'] = $home;
	$local_menu[0]['L_URL'] = $language->main['home'];
	$local_menu[0]['ID_BUTTON'] = 0;
	$template->array_data['L_SERVER_NAME'] = $work->config['description'];
	$template->array_data['L_WELCOME'] = sprintf($language->main['welcome'], $user->data['name']);
	if ($user->id)
	{
		$template->array_data['IF_GUEST_ACCOUNT'] = false;
		$avatar = $user->get_avatar(true);
		$template->array_data['D_AVATAR_WIDTH'] = $avatar['width'] . 'px';
		$template->array_data['D_AVATAR_HEIGHT'] = $avatar['height'] . 'px';
		$template->array_data['U_AVATAR'] = $work->config['site_url'] . '?action=avatar&amp;id=' . $user->id;
		$template->array_data['U_PROFILE'] = $work->config['site_url'] . '?action=profile&amp;id=' . $user->id;
		$template->array_data['L_PROFILE'] = $language->main['profile'];
		$template->array_data['L_FACTION'] = $language->main['user_faction'];
		$template->array_data['L_ALLIANCE'] = $language->main['user_alliance'];
		$template->array_data['L_GROUP'] = $language->main['user_group'];
		$template->array_data['L_MESSAGES'] = $language->main['user_messages'];
		$template->array_data['L_REPORTS'] = $language->main['user_reports'];
		$template->array_data['D_USERNAME'] = $user->data['name'];
		$template->array_data['D_FACTION'] = $language->local_faction($user->data['faction_name']);
		$template->array_data['D_GROUP'] = $user->data['group_name'];
		if ($user->data['alliance'])
		{
			$template->array_data['D_ALLIANCE'] = $user->alliance['name'] . '&nbsp;(' . $user->alliance['title'] . ')';
		}
		else
		{
			$template->array_data['D_ALLIANCE'] = '-';
		}
		$template->array_data['D_MESSAGES'] = '0';
		$template->array_data['D_NEW_MESSAGES'] = '0';
		$template->array_data['D_REPORTS'] = '0';
		$template->array_data['D_NEW_REPORTS'] = '0';
	}
	else
	{
		$template->array_data['IF_GUEST_ACCOUNT'] = true;
		$template->array_data['U_LOGIN'] = $work->config['site_url'] . '?action=login';
		$template->array_data['L_INPUT_LOGIN'] = $language->main['input_login'];
		$template->array_data['L_LOGIN'] = $language->main['user_login'];
		$template->array_data['L_PASSWORD'] = $language->main['user_pass'];
		$template->array_data['L_LOGIN_SERVER'] = $language->main['login_server'];
		$template->array_data['D_LOGIN'] = '';
		if (isset($_SESSION['user_login']) && !empty($_SESSION['user_login']))
		{
			$template->array_data['D_LOGIN'] = $_SESSION['user_login'];
			unset($_SESSION['user_login']);
		}
	}
	$news_serv = SERVER_NO;
	$template->array_data['D_STATISTIC_SERVER'] = $language->main['statistic_server'];
	$template->array_data['D_STATISTIC_USER'] = sprintf($language->main['statistic_user'], $static['all_user'], $work->config['online_user_last_hour'], $static['activ_user']);
	$template->array_data['D_STATISTIC_ALLIANCE'] = sprintf($language->main['statistic_alliance'], $static['all_alliance'], $static['user_in_alliance']);
}
else
{
	$template->array_data['L_SPINNER'] = $language->main['spinner'];
	$template->array_data['L_GO_TO_SERVER'] = $language->main['go_to_server'];
	$result = $work->list_server();
	if ($result)
	{
		$i = 0;
		foreach ($result as $server)
		{
			$template->array_data['ARRAY_URL'][$i]['ID_SERV'] = $server['id'];
			$template->array_data['ARRAY_URL'][$i]['L_URL'] = $server['name'];
			$template->array_data['ARRAY_URL'][$i]['L_DESC'] = $server['description'];
			$template->array_data['ARRAY_STATISTIC'][$i]['ID_SERV'] = $server['id'];
			$template->array_data['ARRAY_STATISTIC'][$i]['U_URL'] = str_replace(GetEnv("HTTP_HOST"), 's' . $server['id'] . '.' . GetEnv("HTTP_HOST"), $config['site_url']);
			$template->array_data['ARRAY_STATISTIC'][$i]['L_DESC'] = $server['description'];
			$template->array_data['ARRAY_STATISTIC'][$i]['D_STATISTIC_SERVER'] = $language->main['statistic_server'];
			$template->array_data['ARRAY_STATISTIC'][$i]['D_STATISTIC_USER'] = sprintf($language->main['statistic_user'], $static[$server['id']]['all_user'], $work->config['online_user_last_hour'], $static[$server['id']]['activ_user']);
			$template->array_data['ARRAY_STATISTIC'][$i]['D_STATISTIC_ALLIANCE'] = sprintf($language->main['statistic_alliance'], $static[$server['id']]['all_alliance'], $static[$server['id']]['user_in_alliance']);
			$i++;
		}
	}
	else
	{
		die ('No configured server!');
	}
	$news_serv = 0;
}
$db->select('*', DB_WORK, TBL_NEWS);
$db->where('`id_server` = ' . $news_serv);
$db->order('datetime', 'down');
$db->limit($work->config['main_news']);
$db->query();
$result = $db->res_arr();
$db->clean();
if ($result)
{
	$i = 0;
	foreach ($result as $news)
	{
		$template->array_data['ARRAY_NEWS'][$i]['D_SUBJECT'] = $news['subject'];
		$template->array_data['ARRAY_NEWS'][$i]['L_DATA'] = $language->main['data'];
		$template->array_data['ARRAY_NEWS'][$i]['D_DATATIME'] = $news['datetime'];
		$template->array_data['ARRAY_NEWS'][$i]['D_TEXT'] = $news['text'];
		$i++;
	}
}
?>
